const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const packageinfo = require(path.resolve(__dirname, '../package.json'));
var config ={
    entry: { heter: "./src/index.js" },
    output: {
        filename: `[name]_${packageinfo.version}.js`,
        path: path.resolve(__dirname, '../dist'),
        clean: true,
    },
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader,
                        options: {
                            publicPath: '../'
                        }
                    },
                    "css-loader",
                    "sass-loader"
                ]
            }
        ]
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: `[name]_${packageinfo.version}.css`
        }),
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: path.resolve(__dirname, '../index.html'),
        })
    ],
    devServer: {
        contentBase: './dist/index.html',
        open: true,
        hot: true
    },
}
module.exports = (env, argv) => {
    if (argv.mode === 'development') {
        config.devtool = 'source-map';
        config.output.publicPath = '/'
    }

    if (argv.mode === 'production') {
        config.output.publicPath = './'
    }
    config.mode = argv.mode;
    return config;
};
